package initialize

import (
	"github.com/olivere/elastic/v7"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
	"week3/projectsrv/global"
)

func Init() {
	EsInit()
	MysqlInit()
}
func EsInit() {
	var (
		err error
		dsn = "http://127.0.0.1:9277"
	)
	global.EsClient, err = elastic.NewClient(elastic.SetURL(dsn), elastic.SetSniff(false))
	if err != nil {
		panic(err)
	}
}
func MysqlInit() {
	var err error
	dsn := "root:root@tcp(127.0.0.1:3306)/blog?charset=utf8mb4&parseTime=True&loc=Local"
	global.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
			TablePrefix:   "week3_",
		},
	})
	if err != nil {
		panic(err)
	}
}
